package com.rimi.commons;

import lombok.Data;

/**
 *  返回消息的结果类
 * @Author luc
 * @Date 2021/6/7
 */
@Data
public class CommonResult<T> {

    private int code;

    private String message;

    private T data;

    public CommonResult(ResultCode resultCode, T data) {
        this.code = resultCode.getCode();
        this.message = resultCode.getMsg();
        this.data = data;

    }

    /**
     *  成功的消息返回值
     * @param data 成功的返回结果
     * @return
     */
    public  static <E> CommonResult<E> onSuccess(E data) {
        return new CommonResult<>(ResultStatus.OK, data);
    }

    /**
     *  失败的回调
     * @param resultCode 失败的原因
     * @return
     */
    public  static <E> CommonResult<E> onFailed(ResultCode resultCode) {
        return new CommonResult<>(resultCode,null);
    }
}
